import request from "./request";
import {
  CreateApplicationReq,
  CreateCategoryReq,
  CreateProductReq,
  CreatePurchaseNotificationReq,
  CreatePurchaseOrderReq,
  CreateReturnApplicationReq,
  CreateSupplierReq,
  CreateUserReq,
  CreateWarehouseProductReq,
  CreateWarehouseRecordReq,
  CreateWarehouseReq,
  DeleteCategoryReq,
  DeleteProductReq,
  DeletePurchaseOrderReq,
  DeleteSupplierReq,
  DeleteUserReq,
  DeleteWarehouseProductReq,
  DeleteWarehouseRecordReq,
  DeleteWarehouseReq,
  GetUserReq,
  ListApplicationsReq,
  ListCategoriesReq,
  ListProductsReq,
  ListPurchaseNotificationReq,
  ListPurchaseOrdersReq,
  ListRolesReq,
  ListSuppliersReq,
  ListUsersReq,
  ListWarehouseProductsReq,
  ListWarehousesReq,
  LoginReq,
  LoginResp,
  ModifyPasswordReq,
  RegisterReq,
  ResetPasswordReq,
  UpdateApplicationStatusReq,
  UpdateCategoryReq,
  UpdateProductReq,
  UpdatePurchaseOrderReq,
  UpdateSupplierReq,
  UpdateWarehouseProductReq,
  UpdateWarehouseRecordReq,
  UpdateWarehouseReq,
} from "./type/ckgl";

// 登陆
export function loginCkgl(data: Partial<LoginReq>) {
  return request<LoginResp>("/api/wms/v1/user/login", {
    method: "POST",
    data,
  });
}

export function Logout(data: Partial<any>) {
  return request<any>("/api/wms/v1/user/logout", {
    method: "POST",
    data,
  });
}

// 注册
export function register(data: Partial<RegisterReq>) {
  return request<any>("/api/wms/v1/user/register", {
    method: "POST",
    data,
  });
}

// 创建用户（系统管理员）
export function createUser(data: Partial<CreateUserReq>) {
  return request<any>("/api/wms/v1/user/create", {
    method: "POST",
    data,
  });
}

// 删除用户 (系统管理员)
export function deleteUser(data: Partial<DeleteUserReq>) {
  return request<any>("/api/wms/v1/user/delete", {
    method: "POST",
    data,
  });
}

// 重置用户密码（系统管理员）
export function resetPassword(data: Partial<ResetPasswordReq>) {
  return request<any>("/api/wms/v1/user/password/reset", {
    method: "POST",
    data,
  });
}

// 修改密码
export function modifyPassword(data: Partial<ModifyPasswordReq>) {
  return request<any>("/api/wms/v1/user/password/modify", {
    method: "POST",
    data,
  });
}

export function updateUserRole(data: Partial<any>) {
  return request<any>("/api/wms/v1/user/role/update", {
    method: "POST",
    data,
  });
}

// 给用户添加角色
export function addRolesToUser(data: Partial<ModifyPasswordReq>) {
  return request<any>("/api/wms/v1/user/role/add", {
    method: "POST",
    data,
  });
}

// 用户列表
export function listUsers(params: Partial<ListUsersReq>) {
  return request<any>("/api/wms/v1/user/list", {
    method: "GET",
    params,
  });
}

// 用户详情
export function getUser(params: Partial<GetUserReq>) {
  return request<any>("/api/wms/v1/user/detail", {
    method: "GET",
    params,
  });
}

// 角色列表
export function listRoles(params: Partial<ListRolesReq>) {
  return request<any>("/api/wms/v1/role/list", {
    method: "GET",
    params,
  });
}

// 用户权限列表
export function listUserOperations(params: Partial<ListRolesReq>) {
  return request<any>("/api/wms/v1/user/operations", {
    method: "GET",
    params,
  });
}

// 创建物品
export function createProduct(data: Partial<CreateProductReq>) {
  return request<any>("/api/wms/v1/product/create", {
    method: "POST",
    data,
  });
}

// 更新物品
export function updateProduct(data: Partial<UpdateProductReq>) {
  return request<any>("/api/wms/v1/product/update", {
    method: "POST",
    data,
  });
}

// 删除物品
export function deleteProduct(data: Partial<DeleteProductReq>) {
  return request<any>("/api/wms/v1/product/delete", {
    method: "POST",
    data,
  });
}

// 物品列表
export function listProducts(params: Partial<ListProductsReq>) {
  return request<any>("/api/wms/v1/product/list", {
    method: "GET",
    params,
  });
}

// 创建物品种类
export function createCategory(data: Partial<CreateCategoryReq>) {
  return request<any>("/api/wms/v1/category/create", {
    method: "POST",
    data,
  });
}

// 删除物品种类
export function updateCategory(data: Partial<UpdateCategoryReq>) {
  return request<any>("/api/wms/v1/category/update", {
    method: "POST",
    data,
  });
}

// 更新物品种类（数量和阈值）
export function deleteCategory(data: Partial<DeleteCategoryReq>) {
  return request<any>("/api/wms/v1/category/delete", {
    method: "POST",
    data,
  });
}

// 物品种类列表
export function listCategories(params: Partial<ListCategoriesReq>) {
  return request<any>("/api/wms/v1/category/list", {
    method: "GET",
    params,
  });
}

// 创建供应商
export function createSupplier(data: Partial<CreateSupplierReq>) {
  return request<any>("/api/wms/v1/supplier/create", {
    method: "POST",
    data,
  });
}

// 更新供应商
export function updateSupplier(data: Partial<UpdateSupplierReq>) {
  return request<any>("/api/wms/v1/supplier/update", {
    method: "POST",
    data,
  });
}

// 删除供应商
export function deleteSupplier(data: Partial<DeleteSupplierReq>) {
  return request<any>("/api/wms/v1/supplier/delete", {
    method: "POST",
    data,
  });
}

// 供应商列表
export function listSuppliers(params: Partial<ListSuppliersReq>) {
  return request<any>("/api/wms/v1/supplier/list", {
    method: "GET",
    params,
  });
}

// 创建采购订单
export function createPurchaseOrder(data: Partial<CreatePurchaseOrderReq>) {
  return request<any>("/api/wms/v1/purchase/order/create", {
    method: "POST",
    data,
  });
}

// 更新采购订单
export function updatePurchaseOrder(data: Partial<UpdatePurchaseOrderReq>) {
  return request<any>("/api/wms/v1/purchase/order/update", {
    method: "POST",
    data,
  });
}

// 删除采购订单
export function deletePurchaseOrder(data: Partial<DeletePurchaseOrderReq>) {
  return request<any>("/api/wms/v1/purchase/order/delete", {
    method: "POST",
    data,
  });
}

// 采购订单列表
export function listPurchaseOrders(params: Partial<ListPurchaseOrdersReq>) {
  return request<any>("/api/wms/v1/purchase/order/list", {
    method: "GET",
    params,
  });
}

// 创建采购通知
export function createPurchaseNotification(
  data: Partial<CreatePurchaseNotificationReq>
) {
  return request<any>("/api/wms/v1/purchase/notification/create", {
    method: "POST",
    data,
  });
}

// 采购通知列表
export function listPurchaseNotification(
  params: Partial<ListPurchaseNotificationReq>
) {
  return request<any>("/api/wms/v1/purchase/notification/list", {
    method: "GET",
    params,
  });
}

// 创建归还申请
export function createReturnApplication(
  data: Partial<CreateReturnApplicationReq>
) {
  return request<any>("/api/wms/v1/return_application/create", {
    method: "POST",
    data,
  });
}

// 更改归还申请状态
export function updateReturnApplicationStatus(
  data: Partial<CreateReturnApplicationReq>
) {
  return request<any>("/api/wms/v1/return_application/update", {
    method: "POST",
    data,
  });
}

// 归还申请列表
export function listReturnApplications(params: Partial<any>) {
  return request<any>("/api/wms/v1/return_application/list", {
    method: "GET",
    params,
  });
}

// 创建申请
export function createApplication(data: Partial<CreateApplicationReq>) {
  return request<any>("/api/wms/v1/application/create", {
    method: "POST",
    data,
  });
}

// 更改申请状态
export function updateApplicationStatus(
  data: Partial<UpdateApplicationStatusReq>
) {
  return request<any>("/api/wms/v1/application/update", {
    method: "POST",
    data,
  });
}

// 申请列表
export function listApplications(params: Partial<ListApplicationsReq>) {
  return request<any>("/api/wms/v1/application/list", {
    method: "GET",
    params,
  });
}

// 创建仓库
export function createWarehouse(data: Partial<CreateWarehouseReq>) {
  return request<any>("/api/wms/v1/warehouse/create", {
    method: "POST",
    data,
  });
}

// 更新仓库
export function updateWarehouse(data: Partial<UpdateWarehouseReq>) {
  return request<any>("/api/wms/v1/warehouse/update", {
    method: "POST",
    data,
  });
}

// 删除仓库
export function deleteWarehouse(data: Partial<DeleteWarehouseReq>) {
  return request<any>("/api/wms/v1/warehouse/delete", {
    method: "POST",
    data,
  });
}

// 仓库列表
export function listWarehouses(params: Partial<ListWarehousesReq>) {
  return request<any>("/api/wms/v1/warehouse/list", {
    method: "GET",
    params,
  });
}

// 创建仓库记录
export function createWarehouseRecord(data: Partial<CreateWarehouseRecordReq>) {
  return request<any>("/api/wms/v1/warehouse/record/create", {
    method: "POST",
    data,
  });
}

// 更新仓库记录
export function updateWarehouseRecord(data: Partial<UpdateWarehouseRecordReq>) {
  return request<any>("/api/wms/v1/warehouse/record/update", {
    method: "POST",
    data,
  });
}

// 删除仓库记录
export function deleteWarehouseRecord(data: Partial<DeleteWarehouseRecordReq>) {
  return request<any>("/api/wms/v1/warehouse/record/delete", {
    method: "POST",
    data,
  });
}

// 仓库记录列表
export function listWarehouseRecords(params: Partial<any>) {
  return request<any>("/api/wms/v1/warehouse/record/list", {
    method: "GET",
    params,
  });
}


// 仓库商品管理
// 仓库商品列表
export function listWarehouseProducts(
  params: Partial<ListWarehouseProductsReq>,
) {
  return request<any>(
    '/api/wms/v1/warehouse/product/list',
    {
      method: 'GET',
      params,
    }
  );
}

// 仓库商品创建
export function createWarehouseProduct(
  data: Partial<CreateWarehouseProductReq>,
) {
  return request<any>(
    '/api/wms/v1/warehouse/product/create',
    {
      method: 'POST',
      data,
    }
  );
}

// 仓库商品更新
export function updateWarehouseProduct(
  data: Partial<UpdateWarehouseProductReq>,
) {
  return request<any>(
    '/api/wms/v1/warehouse/product/update',
    {
      method: 'POST',
      data,
    }
  );
}

// 仓库商品删除
export function deleteWarehouseProduct(
  data: Partial<DeleteWarehouseProductReq>,
) {
  return request<any>(
    '/api/wms/v1/warehouse/product/delete',
    {
      method: 'POST',
      data,
    }
  );
}